<template>
	<view class="demo-button">
		
		
		<cl-card label="隐私清理">
			<cl-row>
				<view @click="clearuser">
					<cl-col>
						<cl-button type="primary" round>
							<text>清理用户({{usercount}})</text>
						</cl-button>
					</cl-col>
				</view>
				<view @click="clearmessage">
					<cl-col>
						<cl-button type="primary" round>
							<text>清理聊天记录({{messagecount}})</text>
						</cl-button>
					</cl-col>
				</view>
				<view @click="clearfiles">
					<cl-col>
						<cl-button type="primary" round>
							<text>清理上传文件</text>
						</cl-button>
					</cl-col>
				</view>
				<!-- <view @click="updatePwd">
					<cl-col>
						<cl-button type="primary" round>
							<text>修改登录密码</text>
						</cl-button>
					</cl-col>
				</view> -->
			</cl-row>
		</cl-card>
		
		<cl-row>
			<cl-input v-model="newpwd" placeholder="">
				<!-- <view slot="prepend">
					<cl-select
						v-model="val5"
						:options="options.city"
					></cl-select>
				</view> -->
				<!-- <view> -->
					<cl-button type="primary" size="mini" slot="append" @click="updatePwd"
						>修改登录密码</cl-button
					>
				<!-- </view> -->
			</cl-input>
		</cl-row>
		
		<!-- <cl-card label="基本用法"> -->
			<cl-loading-mask
				:loading="loading"
				text="处理中"
				color="#000"
				fullscreen
			></cl-loading-mask>
			<!-- <cl-button @tap="open()" size="small">
				<text>全屏</text>
			</cl-button> -->
		<!-- </cl-card> -->
		<cl-message ref="message"></cl-message>
		
		
		
	</view>
</template>

<script>
	import http from '@/common/requestConfig.js';
export default {
	components: {
		http
	},
	data() {
		return {
			usercount:0,
			messagecount:0,
			loading: false,
			newpwd:""
		};
	},
	onLoad() {
		var that = this;
		http.post("customer/GetAllRecord", {}
		).then(res => {
			if(res.code == 1){
				res = res.data;
				that.usercount = res.usercount;
				that.messagecount = res.messagecount;
				//console.log(res);
			}
		}).catch(res=>{
			//console.log('throw error..');
			//that.LoginInfo();
		});
	},
	methods:{
		clearuser(){
			var that = this;
			uni.showModal({
				title:"系统提示",
				content:"将会清空所有的用户信息，确认操作?",
				success: function (res) {
				    if (res.confirm) {
				       that.loading = true;
					   http.post("customer/ClearAllUser",{}
						).then(res => {
							that.loading = false;
							if(res.code == 1){
								that.openModel('success',res.message);
							}else{
								uni.showModal({
									title:"系统提示",
									content:res.message
								})
							}
					   }).catch(res=>{
					   	//console.log('throw error..');
					   	//that.LoginInfo();
					   });
				    }
				}
			})
			
		},
		clearmessage(){
			var that = this;
			uni.showModal({
				title:"系统提示",
				content:"将会清空所有的聊天记录，确认操作?",
				success: function (res) {
				    if (res.confirm) {
				       that.loading = true;
					   http.post("customer/ClearAllMessage",{}
						).then(res => {
							that.loading = false;
							if(res.code == 1){
								that.openModel('success',res.message);
							}else{
								uni.showModal({
									title:"系统提示",
									content:res.message
								})
							}
					   }).catch(res=>{
					   	//console.log('throw error..');
					   	//that.LoginInfo();
					   });
				    }
				}
			})
		},
		clearfiles(){
			var that = this;
			uni.showModal({
				title:"系统提示",
				content:"将会清空所有的聊天文件，确认操作?",
				success: function (res) {
				    if (res.confirm) {
				       that.loading = true;
					   http.post("customer/ClearAllUploadFiles",{}
						).then(res => {
							that.loading = false;
							if(res.code == 1){
								that.openModel('success',res.message);
							}else{
								uni.showModal({
									title:"系统提示",
									content:res.message
								})
							}
					   }).catch(res=>{
					   	//console.log('throw error..');
					   	//that.LoginInfo();
					   });
				    }
				}
			})
		},
		updatePwd(){
			var that = this;
			uni.showModal({
				title:"系统提示",
				content:"确认修改密码?",
				success: function (res) {
				    if (res.confirm) {
				       that.loading = true;
					   http.post("customer/UpdatePwd",{newpwd:that.newpwd}
						).then(res => {
							that.loading = false;
							if(res.code == 1){
								that.openModel('success',res.message);
							}else{
								uni.showModal({
									title:"系统提示",
									content:res.message
								})
							}
					   }).catch(res=>{
					   	//console.log('throw error..');
					   	//that.LoginInfo();
					   });
				    }
				}
			})
		},
		openModel(type,message, options) {
			this.$refs["message"].open({
				type,
				message: message,
				...options,
			});
		},
	}
};
</script>

<style lang="scss">
.demo-button {
	.cl-button {
		// margin-bottom: 20rpx;
	}
}
</style>
